package com.example.holes;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

public class Health {
	private int max = 100;
	private int current = 100;
	private boolean dead = false, damaged = false;;
	private final int left = (int)(12 * Global.SCALE_RATIO_W),
						top = (int)(12 * Global.SCALE_RATIO_H),
						right = (int)(262 * Global.SCALE_RATIO_W),
						bottom = (int)(42 * Global.SCALE_RATIO_H);
	Paint paint;
	
	public Health(){
		paint = new Paint();
	}
	
	//setters
	public void damage(int hit){
		current -= hit;
		damaged = true;
		if (current <= 0){
			current = 0;
			dead = true;
		}
	}
	
	public boolean isDead(){ return dead; }
	
	// ==============
	//     DRAW
	// ==============
	public void Draw(Canvas c){
		paint.setColor(Color.BLACK);
        paint.setStrokeWidth(3);
        c.drawRect(left, top, right, bottom, paint);
        paint.setStrokeWidth(0);
        if (damaged){ // flash red if damaged
        	paint.setColor(Color.RED);
        	damaged = false;
        }
        else{
        	paint.setColor(Color.GREEN);
        }
        c.drawRect(left, top, getRightHealth(), bottom, paint );
	}
	
	private int getRightHealth(){
		float percent = (float)current / max;
		return (int)((percent * (right - left)) + left); //262-12
	}
	
	public void plus(int num){
		current += num;
		if (max < current)
			current = max;
	}
}
